﻿using System;
using System.Collections.Generic;
using GeoAPI.Geometries;

namespace NetTopologySuite.GeometriesGraph.Index
{
	public class SimpleEdgeSetIntersector : EdgeSetIntersector
	{
		public override void ComputeIntersections(IList<Edge> edges, SegmentIntersector si, bool testAllSegments)
		{
			foreach (Edge edge in edges)
			{
				foreach (Edge edge2 in edges)
				{
					if (testAllSegments || edge != edge2)
					{
						SimpleEdgeSetIntersector.ComputeIntersects(edge, edge2, si);
					}
				}
			}
		}

		public override void ComputeIntersections(IList<Edge> edges0, IList<Edge> edges1, SegmentIntersector si)
		{
			foreach (Edge e in edges0)
			{
				foreach (Edge e2 in edges1)
				{
					SimpleEdgeSetIntersector.ComputeIntersects(e, e2, si);
				}
			}
		}

		private static void ComputeIntersects(Edge e0, Edge e1, SegmentIntersector si)
		{
			Coordinate[] coordinates = e0.Coordinates;
			Coordinate[] coordinates2 = e1.Coordinates;
			for (int i = 0; i < coordinates.Length - 1; i++)
			{
				for (int j = 0; j < coordinates2.Length - 1; j++)
				{
					si.AddIntersections(e0, i, e1, j);
				}
			}
		}
	}
}
